﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnitTesting = Microsoft.VisualStudio.TestTools.UnitTesting;
using DataType;
using MyGDocsAddIn;
using Google.GData.Client;
using UILibrary;

namespace TestsRegression.Assert
{
    class ShareEditNewDoc : State
    {
        public override void ValidateDataState(string UserName, string Password)
        {
            m_Ui.DoLogin(UserName, Password);
            long count = m_Ui.GetDocumentsCount();
            
            //is there permission to do update
            m_Ui.DoUpdateDocument();
            
            //ASSERT - no errors in above operations, and no new document during update
            UnitTesting.Assert.AreEqual(count, m_Ui.GetDocumentsCount());
        }

        public override void ValidateUIState()
        {
            MyGDocsForm form = m_Ui.GetUIAccessPoint();
            UnitTesting.Assert.AreEqual(true, form.ShareButton.Enabled);
            UnitTesting.Assert.AreEqual(true, form.UpdateBtn.Enabled);
        }
    }

    class ShareViewNewDoc : State
    {
        public override void ValidateDataState(string UserName, string Password)
        {
            m_Ui.DoLogin(UserName, Password);
            long count = m_Ui.GetDocumentsCount();

            //is there permission to do update
            bool exception = false;
            
            try
            {
                m_Ui.DoUpdateDocument();
            }
            catch (System.Exception ex)
            {
                exception = true;
            }

            //ASSERT user doesn't permission for update
            UnitTesting.Assert.AreEqual(true, exception);
        }

        public override void ValidateUIState()
        {
            MyGDocsForm form = m_Ui.GetUIAccessPoint();
            UnitTesting.Assert.AreEqual(true, form.ShareButton.Enabled);
            UnitTesting.Assert.AreEqual(true, form.UpdateBtn.Enabled);
        }
    }

    class ShareRepeatable : State
    {
        private string[] m_AclList;

        public ShareRepeatable(string[] AclList)
        {
            m_AclList = AclList;
        }

        public override void ValidateDataState(string UserName, string Password)
        {
            m_Ui.DoLogin(UserName, Password);
            long count = m_Ui.GetDocumentsCount();

            //is there permission to do update
            string[] aclList;
            aclList = m_Ui.GetCurrentDocumentAcl();

            //ASSERT
            UnitTesting.Assert.AreEqual(m_AclList.Length + 1, aclList.Length);
        }

        public override void ValidateUIState()
        {
            MyGDocsForm form = m_Ui.GetUIAccessPoint();
            UnitTesting.Assert.AreEqual(true, form.ShareButton.Enabled);
            UnitTesting.Assert.AreEqual(true, form.UpdateBtn.Enabled);
        }
    }
}
